
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class 机器人跳跃问题 {
    static int N = 100010;
    static int[] arr;
    static int n;
    public static void main(String[] args) throws IOException {
       //读入
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintStream out = new PrintStream(System.out);
        n = Integer.parseInt(in.readLine());
        arr = new int[n];
        String[] str = in.readLine().trim().split(" ");
        for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(str[i]);
        //二分
        int l=0;
        int r=100000;
        while(l<r) {
            int m=l+r>>1;
            if(check(m)) r=m;
            else l=m+1;
        }
        System.out.println(l);
    }
    private static boolean check(long e) {

        for(int i=0;i<n;i++) {
            e=e*2-arr[i];
           // if(e>1e+5) return true;
            if(e<0) return false;
        }
        return true;
    }
}